		TITLE	LDATA - Copyright (c) SLR Systems 1991

		INCLUDE	MACROS
		INCLUDE	FIX2TEMP

		PUBLIC	EXE_OUT_LDATA,MOVE_LDATA_1,MOVE_LDATA_2,MOVE_LDATA_3

		.DATA

	SOFT	EXTW	EXETABLE

	SOFT	EXTD	HIGH_WATER

		.CODE	PASS2_TEXT

	SOFT	EXTP	LIDATA_PROC,SHL_DXDI_PAGESHIFT_DI,CONVERT_SUBBX_TO_ES,ERR_NAME_ESDI_RET

	SOFT	EXTA	DATA_OUTSIDE_SEGMOD_ERR

		ASSUME	DS:NOTHING

LIDATA_TYPE	PROC
		;
		;
		;
		CALL	LIDATA_PROC
		FIXES
		RET

LIDATA_TYPE	ENDP

EXE_OUT_LDATA	PROC
		;
		;LDATA_PTR ETC IS RECORD TO BE WRITTEN TO SEGMOD-SPACE
		;SIMPLY MOVE IT IN ONE OR TWO BLOCK MOVES...
		;
if	fg_rom
		BITT	OMITTING_SEGMENT
		JNZ	9$
endif
		LDS	SI,FIX2_LDATA_PTR
		MOV	DI,FIX2_LDATA_LOC.LW
		MOV	DX,FIX2_LDATA_LOC.HW
		TEST	FIX2_LD_TYPE,MASK BIT_LI
		JNZ	LIDATA_TYPE		;OOPS, SPECIAL
		MOV	CX,FIX2_LD_LENGTH

MOVE_LDATA_1	LABEL	PROC

		ADD	DI,CX			;MAKE SURE THIS RECORD DOESN'T
		ADC	DX,0			;WRITE OUTSIDE SEGMOD SIZE
		CMP	FIX2_SM_LEN.HW,DX	;COMPARE HIGH WORD
		JC	MOVE_LDATA_FAIL
		JNZ	GOOD
		CMP	FIX2_SM_LEN.LW,DI
		JC	MOVE_LDATA_FAIL
GOOD:
;		BITT	DEBUG_RECORD
;		JNZ	OHW			;DON'T SET HIGH WATER

if	fg_rom
;		ADD	DI,FIX2_PHASE_ADDR.LW
;		ADC	DX,FIX2_PHASE_ADDR.HW
endif
		;OK, GET READY FOR THE BIG MOVE
		;CHECK ON HIGH-WATER MARK
		CMP	HIGH_WATER.HW,DX
		JC	NHW
		JNZ	OHW
		CMP	HIGH_WATER.LW,DI
		JAE	OHW
NHW:
		MOV	HIGH_WATER.LW,DI
		MOV	HIGH_WATER.HW,DX
OHW:
		SUB	DI,CX
		SBB	DX,0

MOVE_LDATA_2	LABEL	PROC

		;
		;DX:DI IS TARGET ADDRESS
		;
		SUB	DI,FIX2_SM_START.LW	;DELTA FOR CURRENT SEGMOD...
		SBB	DX,FIX2_SM_START.HW

MOVE_LDATA_3	LABEL	PROC

		;
		;CX IS # OF BYTES
		;DS:SI IS SOURCE RECORD
		;
		CALL	SHL_DXDI_PAGESHIFT_DI
		MOV	AX,PAGE_SIZE
		SUB	AX,DI			;CAN WE DO THIS IN ONE MOVE?
		MOV	BX,DX
		ADD	BX,BX
		ADD	BX,OFF EXETABLE
		CMP	AX,CX
		JC	TWO			;NOPE, NEED TWO
TWO_1:
		CALL	CONVERT_SUBBX_TO_ES	;GET ES PTR
		BITT	MOVE_BYTES
		JNZ	6$
		SHR	CX,1
		REP	MOVSW
		ADC	CX,CX
6$:
		REP	MOVSB
		FIXES
9$:
		RET

MOVE_LDATA_FAIL:
		LES	DI,FIX2_SEG_NAME
		MOV	CL,DATA_OUTSIDE_SEGMOD_ERR
		CALL	ERR_NAME_ESDI_RET
		FIXES
		RET

TWO:
		;
		;OOPS, CROSSES A 16K BLOCK BOUNDARY...	DO TWO MOVES
		;
		CALL	TWO_PROC
		JMP	TWO_1

EXE_OUT_LDATA	ENDP

TWO_PROC	PROC	NEAR
		;
		;
		;
		XCHG	AX,CX
		SUB	AX,CX
		PUSH	AX			;THIS MANY NEXT TIME...
		PUSH	BX
		CALL	CONVERT_SUBBX_TO_ES
		POP	BX
		BITT	MOVE_BYTES
		JNZ	7$
		SHR	CX,1
		REP	MOVSW
		ADC	CX,CX
7$:
		REP	MOVSB
		POP	CX
		INC	BX
		INC	BX			;NEXT LOGICAL BLOCK
		XOR	DI,DI
		RET

TWO_PROC	ENDP

		END

